#ifndef _FX_LICENSE_
#define _FX_LICENSE_

/** 
* Check whether license information is valid
*
* @param[in]	pSN				Serial number (with product code), required
* @param[in]	pModules		Module codes, or NULL if none
* @param[in]	pnUsers			Number of users (in text format), required
* @param[in]	pLicensee		Licensee name, required
* @param[in]	pExpireDate		Expiration date (in "YYYY/MM/DD" format), or NULL if none
* @param[in]	pLicenseDate	License date (in "YYYY/MM/DD" format), required
* @param[in]	pRestrictions	Restrictions for the license, NULL if none
* @param[in]	pSignature		Signature of the license. Required.
* @return Whether license information is valid.
*/

FX_BOOL	FX_CheckLicenseInfo(FX_LPCWSTR pSN,
							FX_LPCWSTR pModules,
							FX_LPCWSTR pnUsers,
							FX_LPCWSTR pLicensee,
							FX_LPCWSTR pExpireDate,
							FX_LPCWSTR pLicenseDate,
							FX_LPCWSTR pRestrictions,
							FX_LPCWSTR pSignature);

//*****************************************************************************
//* License codes
//*****************************************************************************
/**
 * @brief	Macro to combine a valid license atom by two license code a & b.
 *			License code uses 36 characters: from '0' to '9', and from 'A' to 'Z'.
 *			Any other character is invalid and should not use.
 */
#define FX_LICENSEATOM_CODE(c)			(FX_DWORD)(c < 'A' ? c - '0' : c - 55)
#define FX_LICENSEATOM_FROMCODES(a, b)	((FX_LICENSEATOM_CODE(b) << 8) | FX_LICENSEATOM_CODE(a))
/**
 * @brief	Macro to make a license atom from a integer value.
 *			Parameter n is an unsigned integer, and should not exceed 1295, that's from 0 to 1295.
 */
#define FX_LICENSEATOM_FROMVALUE(n)		(((FX_DWORD)(FX_BYTE)(n / 36) << 8) | (FX_DWORD)(n % 36))

/**
 * @brief	Generate a number of register codes.
 * 
 * @param[in] dwProductID		product ID, should be from 0 to 1295.
 * @param[in] dwProductVer		product version, should be from 0 to 1295.
 * @param[in] dwDistributorID	distributor ID, should be from 0 to 1295.
 * @param[in] dwDistributorVer	distributor version, should be from 0 to 1295.
 * @param[in] dwExpiredDays		expiration in days, should be from 0 to 1295, 0 means no limitation.
 * @param[in] dwSNStart			starting serial number for a license, 32bits unsigned integer value, should not be greater than 60466175.
 * @param[in] dwSNCount			count of total serial numbers which will be generated, dwSNStart + dwSNCount should not be greater than 60466175.
 * @param[out] codes			byte string array to store all register codes.
 *
 * @remark	dwProductID, dwProductVer, dwDistributorID, dwDistributorVer, dwExpiredDays have same format.
 *			To set their value, please use macro FX_LICENSEATOM_FROMCODES or FX_LICENSEATOM_FROMVALUE.
 */
void	FX_GenerateLicenseCodes(FX_DWORD dwProductID,
								FX_DWORD dwProductVer,
								FX_DWORD dwDistributorID,
								FX_DWORD dwDistributorVer,
								FX_DWORD dwExpiredDays,
								FX_DWORD dwSNStart,
								FX_DWORD dwSNCount,
								CFX_ByteStringArray &codes);

/**
 * @brief	Verify a given license code and determine whether it's valid or not.
 *
 * @param[in] code	a license code to be verified.
 * @return	TRUE if license code is valid, or FALSE if it's wrong.
 */
FX_BOOL	FX_VerifyLicenseCode(const CFX_ByteString &code);

#endif //_FX_LICENSE_
